#include "restorecheckdialog.h"
#include "ui_restorecheckdialog.h"

RestoreCheckDialog::RestoreCheckDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RestoreCheckDialog)
{
    ui->setupUi(this);
    move(0,0);
    this->setWindowFlags(Qt::FramelessWindowHint);    //无边框
    this->setStyleSheet("outline: none;");            //无虚线框
}

RestoreCheckDialog::~RestoreCheckDialog()
{
    delete ui;
}

void RestoreCheckDialog::loadingState()
{
    ui->cancelBtn->hide();
    ui->sureBtn->hide();

    if(HMI_UPDATE == type)
    {
        ui->label->setText(tr("正在升级,请稍后..."));
    }
    else if(CTRL_UPDATE == type)
    {
        ui->label->setText(tr("正在升级,请稍后..."));
    }
    else if(HMI_RESTORE == type)
    {
        ui->label->setText(tr("正在还原,请稍后..."));
    }
    else if(CTRL_RESTORE == type)
    {
        ui->label->setText(tr("正在还原,请稍后..."));
    }
    else{}

    //return true;
}

void RestoreCheckDialog::showAndSetTitle(int type, QString path)
{
    this->show();
    ui->cancelBtn->show();
    ui->sureBtn->show();

    //get
    this->type = type;
    this->path = path;

    //view
    if(HMI_UPDATE == type)
    {
        ui->label->setText(tr("升级系统会覆盖原系统文件\n是否继续升级?"));
    }
    else if(CTRL_UPDATE == type)
    {
        ui->label->setText(tr("升级系统会覆盖原系统文件\n是否继续升级?"));
    }
    else if(HMI_RESTORE == type)
    {
        ui->label->setText(tr("此操作会清除当前系统文件\n是否继续升级?"));
    }
    else if(CTRL_RESTORE == type)
    {
        ui->label->setText(tr("此操作会清除当前系统文件\n是否继续升级?"));
    }
    else{}
}

void RestoreCheckDialog::on_sureBtn_clicked()
{
    loadingState();//页面改变

    if(HMI_UPDATE == type)
    {
        emit hmiUpdatePathSignal(path);
    }
    else if(CTRL_UPDATE == type)
    {
        emit ctrlUpdatePathSignal(path);
    }
    else if(HMI_RESTORE == type)
    {
        emit hmiRestoreSignal();
    }
    else if(CTRL_RESTORE == type)
    {
        emit ctrlRestoreSignal();
    }
    else{}
}

void RestoreCheckDialog::on_cancelBtn_clicked()
{
    //this->close();
    this->hide();
}
